<?php
class Warehouse_ShelfController extends Zend_Controller_Action
{
	/**
	* 货架列表   
	*
	*/
	private $_s;
	private $_w; //仓库
	private $_a; //仓库分区
	private $_h; //仓库房间	
	public function preDispatch(){
		$this->tplDirectory = "warehouse/shelf/";
		$this->_s=new Warehouse_Service_Shelf();
		$this->_w=new Warehouse_Service_Warehouse();
		$this->_a=new Warehouse_Service_Area();
		$this->_h=new Warehouse_Service_House();		
	}	
	
	public function indexAction(){
		$this->view->OptionChoose=$this->_s->getProductOptionChoose(1);		//产品目录
        $this->view->warehouse=$this->_w->getByCondition(array('warehouse_statu'=>1),'*');	//仓库
        $this->view->warehouse_area=$this->_a->getByCondition('','*','wa_code',0,0);  //仓库
		$this->view->ShelfClass=$this->_s->getShelfClass(array('warehouse_id'=>1,'wsc_status'=>0));	//货架类型
		echo Cff::renderTpl($this->tplDirectory.'index.tpl',"layout");
	}	

	public function listAction(){
		$intpage=$this->_request->getParam('page',1);
		$pageSize=$this->_request->getParam('pageSize');
		$s_ws_code=$this->_request->getParam('s_ws_code','');
		$s_wa_code=$this->_request->getParam('s_wa_code','');
		$s_product_id=$this->_request->getParam('s_product_id','');
		$s_customer_id=$this->_request->getParam('s_customer_id','');
		$s_isEmpty=$this->_request->getParam('s_isEmpty','');
		$s_warehouse_id=$this->_request->getParam('s_warehouse_id','');
		$product_option_choose=$this->_request->getParam('s_product_option_choose','');
        $sortColumn=$this->_request->getParam('sortColumn','');
        $sortMethod=$this->_request->getParam('sortMethod','asc');

		$intpage = ($intpage<1)?1:$intpage;

        //排序
        $sort=array('ws_id desc');
        if($sortColumn!=''){
             $sort=$sortColumn.' '.$sortMethod;
        }

		$condition=array(
			'ws_code_like'=>$s_ws_code,
			'wa_code'=>$s_wa_code,
			'product_sku'=>$s_product_id,
			'customer_id'=>$s_customer_id,
			'warehouse_id'=>$s_warehouse_id,
			'isEmpty'=>$s_isEmpty,
			'poc_id'=>$product_option_choose,
		);
		$count=$this->_s->getBySearchJoinCondition($condition,'count(*)','',0,0);
		$data=array(
			'count'=>0,
			'ask'=>0
			);
		if($count>0){
			$Rows=$this->_s->getBySearchJoinCondition($condition,'*',$sort,$pageSize,$intpage);
			foreach($Rows as $key => $val){
				if(!empty($val['product_id'])){
				    $pspRow=Product_Service_Product::getByProductId($val['product_id']);
				    $Rows[$key]['product_sku']=$pspRow['customer_id']."-".$pspRow['product_sku'];
				}
                //计算占用率
                $rateRow = new Warehouse_Service_OccupancyRate(array('ws_code'=>$val['ws_code']));
                $result=$rateRow->getRate();
                if(isset($result['ask']) && $result['ask']=='1'){
                    $Rows[$key]['rate'] =$result['rate']['total'];
                }
			}
			$data=array(
				'count'=>$count,
				'result'=>$Rows,
				'ask'=>1
			);
		}
		die(Zend_Json::encode($data));
	}
	
	
	public function createAction(){
		$wh_code=trim($this->_request->getPost('wh_code')); //房间号		
		$wa_code=trim($this->_request->getPost('wa_code','')); //仓库区域
		$warehouse_id=$this->_request->getPost('warehouse_id','0'); //仓库
		$ws_statu=$this->_request->getPost('ws_statu','');  //状态
		$ws_note=$this->_request->getPost('ws_note','');  //描述
		$ws_code=trim($this->_request->getPost('ws_code','')); //货架号
		$wsc_code=trim($this->_request->getPost('wsc_code','')); //货架类型
		$ws_id=$this->_request->getPost('ws_id','');
        $ws_sort=$this->_request->getPost('ws_sort','0');
        $session = new Zend_Session_Namespace('userAuth');
		$user_id=$session->userID;
		$date=date("Y-m-d H:i:s");
		$rows=0;
		$error=array();
		$msg=array(
			'ask'=>0,
			'error'=>$error=array('操作失败!')
		);
		$row=array(
			'ws_code'=>$ws_code,
			'wsc_code'=>$wsc_code,
			'wh_code'=>'A1',
			'ws_statu'=>$ws_statu,
			'wa_code'=>$wa_code,
			'warehouse_id'=>$warehouse_id,
			'ws_note'=>$ws_note,
			'ws_create_date'=>$date,
			'ws_id'=>$ws_id,
            'ws_sort'=>$ws_sort
		);
		$error = $this->_s->validator($row);//表单数据验证
        if(!empty($error)){
			$return=array(
				'ask'=>0,
				'error'=>$error,
			);
            die(Zend_Json::encode($return));
        }
        $warehouse=$this->_w->getById($warehouse_id);	//仓库
		$Hrows=$this->_h->getByfield('wh_code',$row['wh_code']);//对应房间号
		$Arows=$this->_a->getByfield('wa_code',$row['wa_code']);//对应仓库区域
		try{
            if(empty($warehouse)){
                $msg['error']=array('仓库不存在!');
                die(Zend_Json::encode($msg));
            }
			if(empty($Hrows)){ 
				$msg['error']=array('房间号'.$row['wh_code'].'不存在!');
			}elseif(empty($Arows)){
				$msg['error']=array('仓库区域'.$row['wa_code'].'不存在!');
			}elseif($ws_id!=''){
				$inforows=$this->_s->getById($ws_id);
				$wmpRow=Warehouse_Service_Products::getByCondition(array('ws_code'=>$ws_code));
				if(!empty($wmpRow) && $wmpRow['wp_status']!='0' ){
					die(Zend_Json::encode(array('ask'=>0,'error'=>array('货架不为空,不允许修改状态!'))));
				}
				if($ws_sort==$inforows['ws_sort'] && $inforows['wsc_code']==$wsc_code && $inforows['ws_note']==$ws_note && $inforows['ws_statu']==$ws_statu){
					$msg['ask']=0; 
					$msg['error']=array('你没有修改任何资料!');
				}else{
					$updateRow=array(
						'wsc_code'=>$wsc_code,
						'ws_statu'=>$ws_statu,
						'ws_note'=>$ws_note,
                        'ws_sort'=>$ws_sort,
						'ws_last_update'=>$date,
					);
					$rows=$this->_s->update($updateRow,$ws_id);
					//记录日志
					$wsl_note="";
					if($inforows['ws_statu']!=$ws_statu){
						$wsl_note.="ws_statu=\"".$inforows['ws_statu']."\"=>\"".$ws_statu."\"|";
					}
					if($inforows['wsc_code']!=$wsc_code){
						$wsl_note.="wsc_code=\"".$inforows['wsc_code']."\"=>\"".$wsc_code."\"|";
					}
                    if($inforows['ws_sort']!=$ws_sort){
                        $wsl_note.="ws_sort=\"".$inforows['ws_sort']."\"=>\"".$ws_sort."\"|";
                    }
					if($inforows['ws_note']!=$ws_note){
						$wsl_note.="ws_note=\"".$inforows['ws_note']."\"=>\"".$ws_note."\"|";
					}
					$RowsLog=array(
						'ws_code'=>$inforows['ws_code'],
						'user_id'=>$user_id,
						'wsl_type'=>0, //基本修改
						'wsl_create_date'=>$date,
						'wsl_ip'=>$this->_s->getIP(),
						'wsl_note'=>$wsl_note,
					);
					$createRows=Warehouse_Service_Shelflog::create($RowsLog);
					$msg['ask']=2; 
					$msg['msg']='修改成功!';
				}
			}else{
				$exist=$this->_s->getByfield('ws_code',$ws_code);//是否存在
				if(!empty($exist)){
					$return=array(
						'ask'=>0,
						'error'=>array("货架号 ".$ws_code." 已存在!"),
					);
					die(Zend_Json::encode($return));
				}
				unset($row['ws_id']);
				$rows=$this->_s->create($row);
				if($rows>0){
					$msg['ask']=1; //添加成功
					$msg['msg']='添加成功!';
				}
			}
		}catch(Zend_Exception $e){
			$msg=array(
				'ask'=>0,
				'error'=>array('操作失败!'),
				'result'=>$e->getMessage(),
			);
		}
		die(Zend_Json::encode($msg));
	}

	/**
	*返回货架详细信息
	*/
	public function infoAction(){
		$t_id=$this->_request->getParam('ws_id');
		$return=array(
			'ask'=>0,
			'result'=>null
		);
		if(!empty($t_id)){
			$s_rows=$this->_s->getById($t_id);
			$w_rows=$this->_w->getById($s_rows['warehouse_id']);//仓库
			if(!empty($w_rows)){
				$s_rows['warehouse_name']=$w_rows['warehouse_name'];
			}
			$return=array(
				'ask'=>1,
				'result'=>$s_rows
			);
		}
		die(Zend_Json::encode($return));
	}
	
	/**
	*返回货架库存详细信息
	*/
	public function infoinventoryAction(){
		$t_id=$this->_request->getParam('product_id');
		$return=array(
			'ask'=>0,
			'result'=>null
		);
		if(!empty($t_id)){
			$p_rows=Warehouse_Service_Products::getByProductId($t_id);
			$return=array(
				'ask'=>1,
				'result'=>$p_rows
			);
		}
		die(Zend_Json::encode($return));
	}

	public function deleteAction(){
		$t_id=$this->_request->getPost('ws_id');
		$rows=0;
		try{
			if(!empty($t_id)){
                $session = new Zend_Session_Namespace('userAuth');
                $user_id=$session->userID;
                $warehouseShelfRow=$this->_s->getById($t_id);
                $RowsLog=array(
                    'ws_code'=>$warehouseShelfRow['ws_code'],
                    'user_id'=>$user_id,
                    'wsl_type'=>0, //基本修改
                    'wsl_create_date'=>date('Y-m-d H:i:s'),
                    'wsl_ip'=>$this->_s->getIP(),
                    'wsl_note'=>'delete shelf',
                );
                $createRows=Warehouse_Service_Shelflog::create($RowsLog);
				$rows=$this->_s->delete($t_id);
			}
			if($rows>0){
				$return=array(
					'ask'=>1,
					'result'=>'成功删除!',
				);
			}else{
				$return=array(
					'ask'=>0,
					'result'=>'删除失败!',
				);
			}
		}catch(Zend_Exception $e){
			$return=array(
				'ask'=>0,
				'result'=>$e->getMessage(),
			);
        }
		die(Zend_Json::encode($return));
	}
	
	public function selectAction(){
		$data=array('ask'=>0);
		$result=$this->_w->getByCondition('','*','',0,0);  //仓库
		if(!empty($result)){
			$data=array(
				'ask'=>1,
				'result'=>$result,
			);
		}
		die(Zend_Json::encode($data));
	}

	/**
	*根据货架号返回货架日志	
	*货架日志列表
	*@return json
	*/		
	public function getshelflogAction(){
		$intpage=$this->_request->getParam('page',1);
		$pageSize=$this->_request->getParam('pageSize');
		$ws_code=$this->_request->getParam('ws_code','');
		$wsl_type=$this->_request->getParam('wsl_type','');
		$intpage = ($intpage<1)?1:$intpage; 
		$condition=array(
			'ws_code'=>$ws_code,
			'wsl_type'=>$wsl_type,
		);
		$count=Warehouse_Service_Shelflog::getByCondition($condition,'count(*)','',0,0);
		$data=array(
			'count'=>0,
			'ask'=>0
			);
		if($count>0){
			$Rows=Warehouse_Service_Shelflog::getByCondition($condition,'*',array('wsl_id desc'),$pageSize,$intpage);
			foreach($Rows as $key => $value){
				$Urow=User_Service_User::getByUserId($value['user_id']);
				$Rows[$key]['user_id']=$Urow['name'];
			}
			$data=array(
				'count'=>$count,
				'ask'=>1,
				'result'=>$Rows,
			);
		}
		die(Zend_Json::encode($data));
	}

	/**
	*批量生成货架	
	*@return boolean
	*/		
	public function batchAction(){
        $warehouse_id = trim($this->_request->getPost('warehouse')); //仓库
        $view = trim($this->_request->getParam('view','0')); //预览
        //$room_number=$this->_request->getPost('room_number');   //房间号
        $room_number = 'A1';
        $prefix = trim($this->_request->getPost('prefix')); //货架前缀
        $room_wa_code = trim($this->_request->getPost('room_wa_code')); //分区
        $room_wsc_code = trim($this->_request->getPost('room_wsc_code')); //货架类型
        $begin_label = trim($this->_request->getPost('begin_label')); //货架起始编号
        $end_label = trim($this->_request->getPost('end_label'));
        $begin_column = trim($this->_request->getPost('begin_column')); //货架起始列
        $end_column = trim($this->_request->getPost('end_column'));
        $begin_row = trim($this->_request->getPost('begin_row')); //货架起始行
        $end_row = trim($this->_request->getPost('end_row'));
        $date = date("Y-m-d H:i:s");
        $begin_label_str = preg_replace('/([^a-zA-Z]+)/i', '', $begin_label);
        $begin_label_int = preg_replace('/([a-zA-Z]+)/i', '', $begin_label);
        $end_label_int = preg_replace('/([a-zA-Z]+)/i', '', $end_label);
        $ws_sort=$this->_request->getPost('batch_ws_sort','0');
        $ws_note=$this->_request->getPost('batch_ws_note','0');
		$error=array();
		$formdata=array(
			'wh_code'=>$room_number,//默认 A1
            'warehouse_id'=>$warehouse_id,
			'wsc_code'=>$room_wsc_code,
			'wa_code'=>$room_wa_code,
			'begin_label'=>$begin_label,
			'end_label'=>$end_label,
			'begin_column'=>$begin_column,
			'end_column'=>$end_column,
			'begin_row'=>$begin_row,
			'end_row'=>$end_row,
            'ws_sort'=>$ws_sort,
		);
		$error = $this->_s->batchvalidator($formdata);//表单数据验证
        if(!empty($error)){
			$return=array(
				'ask'=>0,
				'error'=>$error,
			);
            die(Zend_Json::encode($return));
        }
		try{
			$label_count=($end_label_int-$begin_label_int);
			$label_arr=array(); //货架编号数组
			for($i=0;$i<=$label_count;$i++){
				$label_arr[]=$prefix.$begin_label_str.($begin_label_int+$i);
			}		
			$column_count=ord($end_column)-ord($begin_column);
			$column_arr=array();  //货架列数组
			$column_str=ord($begin_column);
			for($i=0;$i<=$column_count;$i++){
				$column_arr[]=chr($column_str++);
			}		
			$label_column=array(); //最终货架编号数组
			foreach($label_arr as $la){
				foreach($column_arr as $co){
					for($i=$begin_row;$i<=$end_row;$i++){
						$label_column[]=$la.$co.$i;
					}
				}	
			}
			$allnum=count($label_column);//生成创建数量
            if($view=='1'){
                $return=array(
                    'ask'=>1,
                    'total'=>$allnum,
                    'result'=>$label_column
                );
                die(Zend_Json::encode($return));
            }
			$errNum=0;//失败创建数量
            $succNum=0;//成功创建数量
            $ws_code_err=array();//记录失败货架
			foreach($label_column as $value){
				$row=array(
					'ws_code'=>$value,
					'wh_code'=>$room_number,
					'wsc_code'=>$room_wsc_code,
					'ws_statu'=>1,
					'wa_code'=>$room_wa_code,
					'warehouse_id'=>$warehouse_id,
					'ws_create_date'=>$date,
                    'ws_sort'=>$ws_sort,
                    'ws_note'=>$ws_note,
				);
                $error = $this->_s->validator($row);//表单数据验证
                if(!empty($error)){
                    $ws_code_err[]=$value;
                    continue;
                }
				$exist=$this->_s->getByfield('ws_code',$value);//是否存在
				if(!empty($exist)){
                    //$ws_code_err[]=$value;
                    continue;
                }
                if(!$this->_s->create($row)){
                    $errNum+=1;
                    $ws_code_err[]=$value;
                }else{
                    $succNum+=1;
                }
			}
			$return=array(
				'ask'=>1,
				'msg'=>"操作成功,共生成".$allnum."个,成功".$succNum."个,已存在".($allnum-$errNum-$succNum)."个,失败".($errNum)."个!",
                'result'=>join(',',$ws_code_err),
			);
		}catch(Zend_Exception $e){
			$return=array(
				'ask'=>0,
				'error'=>array('批量生成货架失败!'),
				'result'=>$e->getMessage(),
			);
        }	
		
		die(Zend_Json::encode($return));
	}		
	
	public function printAction(){
		
		$t_ids=$this->_request->getParam('ws_ids');
		$printType=$this->_request->getParam('type','A4');

		$result = array();
		if(!empty($t_ids)){
			
			foreach($t_ids as $t_id){				
				$s_rows=$this->_s->getById($t_id);
				$w_rows=$this->_w->getById($s_rows['warehouse_id']);//仓库
				if(!empty($w_rows)){
					$s_rows['warehouse_name']=$w_rows['warehouse_name'];
				}
				
				$con = array(
						'ws_code'=>$s_rows['ws_code'],
						'warehouse_id'=>$s_rows['warehouse_id'],
						);
				$row = Warehouse_Service_Products::getByCondition($con);
// 				print_r($row);exit;
				$s_rows['code'] = "<b>货架号</b>:".$s_rows['ws_code'];
				$s_rows['product_id'] = "";
				$s_rows['category'] = "";
				$s_rows['category_shot'] = "";
				$s_rows['product_ref_sku'] = "";
				$str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                $s_rows['merge'] = '';
                $strWscode=substr($s_rows['ws_code'],-1);
                $s_rows['merge']=$strWscode;

				if($row){
					$productId = $row['product_id'];
					$productInfo = Product_Service_Product::getProductInfo($productId);
					
					if(!empty($productInfo['category'])){
						$s_rows['category'] = substr($str,"".$productInfo['category']['poc_id']-1,1);
						$s_rows['category_shot'] = $productInfo['category']['poc_value_shortname'];
					}
					$s_rows['product_id'] = "<b>SKU</b>:".$productInfo['product_sku'];
					$s_rows['product_ref_sku'] = empty($productInfo['product_ref_sku'])?"":"&nbsp;&nbsp;<b>共卖ID</b>:".$productInfo['product_ref_sku'];
					//$s_rows['product'] = $productInfo;
				}
				$result[] = $s_rows;
			}
		}
// 		print_r($result);exit;
		if($printType=='10x10'){
			//$result = array_chunk($result, 8);
			$this->view->results = $result;
			echo Cff::renderTpl($this->tplDirectory.'print10x10.tpl',"print");
			exit;
        }elseif($printType=='A4x5'){
            $result = array_chunk($result, 5);
            $this->view->results = $result;
            echo Cff::renderTpl($this->tplDirectory.'printA4x5.tpl',"print");
            exit;
        }elseif($printType=='A4x5-merge'){// 货架号 末位0或1 组合在一起
            $result = array_chunk($result, 5);
            $this->view->results = $result;
            echo Cff::renderTpl($this->tplDirectory.'printA4x5-merge.tpl',"print");
            exit;
		}else{
			$result = array_chunk($result, 8);
			$this->view->results = $result;
			echo Cff::renderTpl($this->tplDirectory.'print.tpl',"print");
		}
		
		
	}
	
	/**
	 * 指定SKU货架打印
	 */
	
	public function printbyskuAction(){
		//echo "eee";exit;
		#$t_ids=$this->_request->getParam('ws_ids');
		//获取产品ID
		$condProuctTemp=array(
				'product_ref_sku'=>'1'
				);
		
		$productTemp=Product_Service_Product::getByCondition($condProuctTemp,array('product_id'));
		
		if(!$productTemp){
			die('产品不存在');
		}
		
		//根据产品ID获取货架号
		$RowsByInProuctIds=new Warehouse_Model_Products();
		$getByInProuctIds=$RowsByInProuctIds->getByInProductIds($productTemp,1);
		$wsCodeTemp=array();
		foreach ($getByInProuctIds as $val){
			$wsCodeTemp[]=$val['ws_code'];
		}
		$conWP=array('ws_code'=>$wsCodeTemp);
		
		
		
	   //根据货架号获取ws_id
		$wsRows=Warehouse_Service_Products::getByJoinInWsCodeCon($conWP,'ws.ws_id');
		if(!$wsRows){
			die('没有找到货架');
		}
		$wsIds=array();
		foreach ($wsRows as $v){
			$wsIds[]=$v['ws_id'];
		}
		
		$t_ids=$wsIds;
		
	    $printType=$this->_request->getParam('type','A4x5');
	    
	  
		$result = array();
		if(!empty($t_ids)){
				
			foreach($t_ids as $t_id){
				$s_rows=$this->_s->getById($t_id);
				$w_rows=$this->_w->getById($s_rows['warehouse_id']);//仓库
				if(!empty($w_rows)){
					$s_rows['warehouse_name']=$w_rows['warehouse_name'];
				}
	
				$con = array(
						'ws_code'=>$s_rows['ws_code'],
						'warehouse_id'=>$s_rows['warehouse_id'],
				);
				$row = Warehouse_Service_Products::getByCondition($con);
				// 				print_r($row);exit;
				$s_rows['code'] = "<b>货架号</b>:".$s_rows['ws_code'];
				$s_rows['product_id'] = "";
				$s_rows['category'] = "";
				$s_rows['category_shot'] = "";
				$s_rows['product_ref_sku'] = "";
				$str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
				if($row){
					$productId = $row['product_id'];
					$productInfo = Product_Service_Product::getProductInfo($productId);
						
					if(!empty($productInfo['category'])){
						$s_rows['category'] = substr($str,"".$productInfo['category']['poc_id']-1,1);
						$s_rows['category_shot'] = $productInfo['category']['poc_value_shortname'];
					}
					$s_rows['product_id'] = "<b>SKU</b>:".$productInfo['product_sku'];
					$s_rows['product_ref_sku'] = empty($productInfo['product_ref_sku'])?"":"&nbsp;&nbsp;<b>共卖ID</b>:".$productInfo['product_ref_sku'];
					//$s_rows['product'] = $productInfo;
				}
				$result[] = $s_rows;
				
			}
			
		}
		
		 		
		if($printType=='10x10'){
			//$result = array_chunk($result, 8);
			$this->view->results = $result;
			echo Cff::renderTpl($this->tplDirectory.'print10x10.tpl',"print");
			exit;
		}elseif($printType=='A4x5'){
			$result = array_chunk($result, 5);
			$this->view->results = $result;
			echo Cff::renderTpl($this->tplDirectory.'printA4x5.tpl',"print");
			exit;
		}else{
			$result = array_chunk($result, 8);
			$this->view->results = $result;
			echo Cff::renderTpl($this->tplDirectory.'print.tpl',"print");
		}
	
	
	}
	

    /*
    * 按货架打印产品标签
    */
    public function printProductLabelAction()
    {
        $params = $this->_request->getParams();
		$printType=$this->_request->getParam('type','5x2');
        $rows = array();
        $printRows=array();
        $i=0;
        foreach($params as $key => $param){
            if(strpos($key,"#productid#") !== false){
                $i++;
                $rows[$i]['ws_code']=substr($key,0,strlen(strstr($key,"#productid#"))*-1);
                $rows[$i]['product_id']=substr($key,strpos($key,"#productid#")+11);
                $rows[$i]['quantity'] = $param;
            }
        }
        $result = array();
        $proServiceObj = new Product_Service_Product();
        foreach($rows as $key => $val){
            $product = $proServiceObj->getByProductId($val['product_id']);
            $printRows['product_id']=$val['product_id'];
            $printRows['customer_id']=$product['customer_id'];
            $printRows['customer_id']=$product['customer_id'];
            $printRows['product_sku']=$product['product_sku'];
            $printRows['category']="";
            $category = $proServiceObj->getProductCategory($val['product_id']);
            $category&&$printRows['category']=$category['poc_value'];
            if($val['quantity'] > 0){
            	$printRows['operator_flag']= 1;
            	$printRows['operator']= $val['ws_code'];
            	
            	$result[] = $printRows;
                for($i=0;$i<$val['quantity'];$i++){
//                     if($i!=0){		                     
		            	$printRows['operator_flag']= 0;
		            	$printRows['operator']= '';
//                     }
                    $result[] = $printRows;
                }
            }
        }
        unset($product,$param);
        if($printType=="5x2"){
        	$this->view->results = $result;
        	echo Cff::renderTpl('product/product/print.tpl',"print");
        }else{
        	$result = array_chunk($result,3);
        	//         print_r($result);exit;
        	$this->view->resultsAll = $result;
			echo Cff::renderTpl('product/product/print_new.tpl',"print");
//         	echo Cff::renderTpl($this->tplDirectory.'product-print-new.tpl',"print");
        }
       

    }

    /*
     * 获取当天货架产品
     */
    public function getShelfProductAction(){
        $shelfIds = $this->_request->ws_ids;
        $proServiceObj = new Product_Service_Product();
        $result=array('ask'=>0,'result'=>array());
        $products = array();
        $i=0;
        if(!empty($shelfIds)){
            foreach($shelfIds as $key => $val){
                $shelfRow=Warehouse_Service_Shelf::getById($val);
      
                if (!empty($shelfRow)) {
                    $warehouseProductRow = Warehouse_Service_Products::getByfield('ws_code', $shelfRow['ws_code'], 1);
                    
                    if(!empty($warehouseProductRow)&&$warehouseProductRow['wp_status']!=0){                    	
                    	$product = Product_Service_Product::getByProductId($warehouseProductRow['product_id']);
                    	if($product['product_ref_sku']=="YES"){//共卖 无需打印标签  跳过
                    		continue;
                    	}
                        $i++;
                        $productInfo = $proServiceObj->getProductInfo($warehouseProductRow['product_id']);
                        $products[$i]['ws_code'] = $warehouseProductRow['ws_code'];
                        $products[$i]['customer_id'] = $productInfo['customer_id'];
                        $products[$i]['product_id'] = $productInfo['product_id'];
                        $products[$i]['product_sku'] = $productInfo['product_sku'];
                        //$products[$i]['product_title'] = $productInfo['product_title'];
                        $products[$i]['category'] = $productInfo['category']['poc_value'];
                        $products[$i]['quantity'] = $warehouseProductRow['wp_quantity'] + $warehouseProductRow['wp_quantity_hold'] ;
                    }
                }
            }
        }
        $result=array('ask'=>count($products)>0?1:0,'result'=>$products);
        die(json_encode($result));
    }

}